import Vue from 'vue'
import Vuex from 'vuex'
import {loginDetail,peopleMessage,logOutLogin} from '../api/api'
Vue.use(Vuex)
import { message , notification } from 'ant-design-vue'
Vuex.Store.prototype.$notification = notification;
Vuex.Store.prototype.$message = message;
export default new Vuex.Store({
  state: {
    isLogin:false,
    showHide:false,
    userContent:[]
  },
  mutations: {
    changeLogin(context,payload){
      context.isLogin = payload
    },
    changeMT(context,show){
      context.showHide = show
    },
    //登录用户个人信息
    userContent(state,user){
      state.userContent=user
    }
  },
  gethers:{
    shoppingCartListLength : context=>{
      return context.shoppingCartList.length
    }
  },
  actions: {
    getIsLogin(context,payload){
      loginDetail(payload.userName,payload.passWord).then(res=>{
        context.commit("userContent",res.userInfo)
        console.log(res)
        console.log(context)
        if(res.code != 500){
          context.commit("changeLogin",true),
              context.commit("changeMT",false),
              this.$message.success("登录成功")
        }else{
          context.commit("changeMT",true);
          this.$message.error("登录失败")
        }
      })
    },
    logout(context){
      logOutLogin().then(res=>{
        console.log(res)
        context.commit("changeLogin",false);

      })
    },
    getMessage(context){
      peopleMessage().then(res=>{
        console.log(res)
        context.commit("changeLogin",true);
        context.commit("userContent",res.userInfo)
      })
    }
  },
  modules: {
  }
})
